package wsi.gui.resolve.task;

import java.io.File;

import javafx.concurrent.Task;
import wsi.exp.ExpFolderController;
import wsi.gui.resolve.model.FunctionStatData;
import wsi.gui.resolve.model.FunctionStatTuple;

public class PopulateServiceTask extends Task<FunctionStatData> {

	private final String service;

	public PopulateServiceTask(String service) {
		super();
		this.service = service;
	}

	@Override
	protected FunctionStatData call() throws Exception {
		FunctionStatData data = new FunctionStatData();

		File dir = ExpFolderController.shared().getFolderForExp5();
		File ws_dir = new File(dir, service);

		if (!ws_dir.exists() || !ws_dir.isDirectory())
			return data;

		FunctionStatTuple tuple;

		for (File d : ws_dir.listFiles()) {
			if (!d.isDirectory())
				continue;

			tuple = new FunctionStatTuple(service, d);

			if (!tuple.isValid())
				continue;

			data.add(tuple);
		}

		return data;
	}

}
